package com.carleasoft.mps.cms.business.repairs.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.repairs.bean.entity.RepairsGroup;
import com.carleasoft.mps.cms.business.repairs.bean.entity.RepairsMessage;
import com.carleasoft.mps.cms.business.repairs.bean.po.*;
import com.carleasoft.mps.cms.business.repairs.bean.vo.QueryIsDealPersonVo;
import com.carleasoft.mps.cms.business.repairs.bean.vo.RepairsMessageDetailVo;
import com.carleasoft.mps.cms.business.repairs.bean.vo.RepairsStatisticsVo;
import com.carleasoft.mps.cms.business.repairs.service.RepairsMessageService;
import com.carleasoft.mps.core.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 网上报修 前端控制器
 * </p>
 *
 * @author fan
 * @since 2023-06-02
 */
@RestController
@RequestMapping("/repairsMessage")
public class RepairsMessageController {
    @Autowired
    private RepairsMessageService repairsMessageService;

    /**
     * 网上报修添加接口
     */
    @PostMapping("/repairsAdd")
    public R repairsAdd(@RequestBody RepairsMessageAddOrEditPo repairsMessageAddOrEditPo) {
        return R.ok(repairsMessageService.repairsAdd(repairsMessageAddOrEditPo));
    }

    /**
     * 导入网上报修
     * @param file
     * @return
     */
    @PostMapping("/repairsExcel")
    public R repairsExcel(@RequestPart("file") MultipartFile file) {
        boolean isOk = repairsMessageService.repairsExcel(file);
        return R.ok(isOk);
    }

    /**
     * 网上报修分页接口
     */
    @PostMapping("/repairsPage")
    public R<Page<RepairsMessage>> repairsPage(@RequestBody RepairsMessagePagePo repairsMessagePagePo) {
        return R.ok(repairsMessageService.repairsPage(repairsMessagePagePo));
    }

    /**
     * 我的报修分页接口
     */
    @PostMapping("/myRepairsPage")
    public R<Page<RepairsMessage>> myRepairsPage(@RequestBody RepairsMessagePagePo repairsMessagePagePo) {
        return R.ok(repairsMessageService.myRepairsPage(repairsMessagePagePo));
    }

    /**
     * 网上报修详情接口
     */
    @PostMapping("/repairsDetail")
    public R<RepairsMessageDetailVo> repairsDetail(@RequestBody RepairsMessage repairsMessage) {
        return R.ok(repairsMessageService.repairsDetail(repairsMessage));
    }

    /**
     * 网上报修处理接口
     */
    @PostMapping("/repairsDeal")
    public R<Boolean> repairsDeal(@RequestBody RepairsMessageDealPo repairsMessageDealPo) {
        return R.ok(repairsMessageService.repairsDeal(repairsMessageDealPo));
    }

    /**
     * 网上报修维修反馈接口
     */
    @PostMapping("/repairsFeedback")
    public R<Boolean> repairsFeedback(@RequestBody RepairsFeedbackPo repairsFeedbackPo) {
        return R.ok(repairsMessageService.repairsFeedback(repairsFeedbackPo));
    }

    /**
     * 网上报修派单人员查询
     */
    @PostMapping("/sendPersonList")
    public R<List<RepairsGroup>> sendPersonList(@RequestBody SendPersonListPo sendPersonListPo) {
        return R.ok(repairsMessageService.sendPersonList(sendPersonListPo));
    }

    /**
     * 重新派工接口
     */
    @PostMapping("/anew")
    public R anew(@RequestBody AnewPo anewPo) {
        return R.ok(repairsMessageService.anew(anewPo));
    }

    /**
     * 查询当前登录人是否是综合处理人
     */
    @PostMapping("/queryIsDealPerson")
    public R<QueryIsDealPersonVo> queryIsDealPerson() {
        return R.ok(repairsMessageService.queryIsDealPerson());
    }

    /**
     * 导出报修记录
     */
    @PostMapping("/export")
    public R export(@RequestBody RepairsMessagePagePo repairsMessagePagePo, HttpServletResponse response) {
        return R.ok(repairsMessageService.export(repairsMessagePagePo, response));
    }

    /**
     * 办公统计-网上报修
     */
    @PostMapping("/online/statistics")
    public R<RepairsStatisticsVo> statistics() {
        return R.ok(repairsMessageService.statistics());
    }

    /**
     * 办公统计-网上报修-年度报修数量统计
     */
    @PostMapping("/online/statistics/theYear")
    public R statisticsTheYear() {
        return R.ok(repairsMessageService.statisticsTheYear());
    }

    /**
     * 办公统计-网上报修-维修率统计
     */
    @PostMapping("/online/statistics/MaintainRate")
    public R MaintainRate() {
        return R.ok(repairsMessageService.MaintainRate());
    }
}

